import pandas as pd
from sklearn.cluster import KMeans
from sklearn.preprocessing import LabelEncoder, StandardScaler

data = pd.read_csv("Data (1).csv")
passengers = data[['who', 'alive', 'class', 'age']]
label_encoder = LabelEncoder()
passengers = passengers.apply(
    lambda x: label_encoder.fit_transform(x) if x.name in passengers.columns[0:3] else x).dropna()
passengers.columns = ['who', 'alive', 'class', 'age']
scaler = StandardScaler()
scaled = pd.DataFrame(scaler.fit_transform(passengers), columns=passengers.columns)
kmeans = KMeans(n_clusters=3, random_state=42, n_init=10)
kmeans.fit(scaled)

new_data = pd.DataFrame({'who': [1], 'alive': [0], 'class': [1], 'age': [25]})
predicted_cluster = kmeans.predict(scaler.transform(new_data))
similar = data.loc[scaled.index[kmeans.labels_ == predicted_cluster[0]]]
print(similar)

